<template>
  <div>
    <el-dialog
      v-model="dialogVisible"
      :title="title"
      width="800px"
      @closed="close"
      @open="openfn"
    >
      <div style="line-height: 30px">派单</div>
      <div style="height: 190px">
        <el-scrollbar>
          <div
            v-for="(item, index) in formdata.gtels"
            :key="index"
            class="useritem"
            style="margin-bottom: 10px"
          >
            {{ item.gtel }}
          </div>
        </el-scrollbar>
      </div>
      <div style="line-height: 30px">维修员</div>
      <div class="USearchbox">
        <span
          v-for="(item, key) in USearch"
          :key="key"
          style="height: 30px; padding: 0 10px; line-height: 30px"
        >
          <el-radio v-model="USearchactive" :label="item.uUser">
            {{ item.uUser }}
          </el-radio>
        </span>
      </div>
      <template #footer>
        <el-button :loading="loading" type="primary" @click="updatafn">
          确定
        </el-button>
        <slot name="btnslot"></slot>
        <el-button @click="close">取消</el-button>
      </template>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    name: 'afterlistxjpd',
    components: {},
    data() {
      return {
        dialogVisible: false,
        title: '',
        USearch: [],
        USearchactive: '',
        formdata: { uUser: '', gtels: [] },
        loading: false,
        setgtelsfalg: false,
      }
    },
    mounted() {},
    methods: {
      close() {
        this.dialogVisible = false
      },
      openfn() {},
      async show(gtels = [], asynccallback) {
        this.asynccallback = asynccallback
        this.formdata.gtels = gtels
        let { data } = await this.$z.$axios.post('/USearchDetailed', {
          sutype: `utype in (22)`,
        })
        this.USearch = data
        this.dialogVisible = true
      },
      async updatafn() {
        if (this.USearchactive == '') {
          this.$message.error('请选择用户')
          return
        }
        let reqs = []
        this.formdata.gtels.forEach((e) => {
          reqs.push(
            this.$z.$axios.post('/AfterListXJpd', {
              ...e,
              uUser: this.USearchactive,
            })
          )
        })
        await Promise.all(reqs)
        this.$message.success('操作完成')
        this.loading = false
        this.dialogVisible = false
        this.asynccallback()
      },
    },
  }
</script>
<style lang="scss">
  .USearchbox {
    background: rgba(255, 255, 255, 0.1);
    padding: 20px;
    display: flex;
    flex-wrap: wrap;
  }
</style>
